#define _CRT_SECURE_NO_WARNINGS 1
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    vector<string> ret;
    void _sub(string& str, vector<bool>& vis, string& s)
    {
        if (s.size() == str.size())
        {
            ret.push_back(s);
            return;
        }
        for (int i = 0;i < str.size();++i)
        {
            if (vis[i] == true)
                continue;
            if (i - 1 >= 0 && str[i] == str[i - 1] && vis[i - 1] == false)
                continue;
            s.push_back(str[i]);
            vis[i] = true;
            _sub(str, vis, s);
            s.pop_back();
            vis[i] = false;
        }
    }
    vector<string> Permutation(string str)
    {
        sort(str.begin(), str.end());
        vector<bool> vis(str.size(), false);
        string s;
        _sub(str, vis, s);
        return ret;
    }
};